<template>
  <div class="search_box" @scroll.passive="getScroll($event)">
    <div class="head">
      <div class="box">
        <div class="box-left" @click="homeChange">
          <img src="../images/lucency-logo.png" alt />
        </div>
        <div class="box-wier"></div>
        <div class="box-centent">数字人备案存档</div>
        <div class="box-right" v-if="!token">
          <div class="box-right-box" @click="loginChange">注册/登录</div>
        </div>
        <div class="box-right" v-else>
          <div class="box-right-hint" @click="loginLith">
            <img src="../images/hint.png" alt />
            <div class="box-right-hint-num" v-if="msgTotal>0">{{msgTotal>9? '···':msgTotal}}</div>
          </div>
          <p @click="loginChange">{{ nickname }}</p>
          <div class="box-right-img">
            <img @click="loginChange" :src="avatar" alt height="100%" />
          </div>
        </div>
      </div>
      <div class="search">
        <el-input placeholder="请输入内容" v-model="name" class="input-with-select">
          <!-- <el-button slot="append" icon="el-icon-search" style="width: 66px;color: #fff;"></el-button> -->
        </el-input>
        <div class="search-box" @click="serachChange">
          <img src="../images/search.png" alt />
        </div>
      </div>
    </div>
    <!-- 筛选 -->
    <div class="filtrate">
      <div class="filtrate-box">
        <div class="filtrate-box-title">
          <div class="layout-item-name">数字人属性：</div>
          <el-radio-group v-model="attrValue" @input="serachChange">
            <el-radio
              v-for="(item,index) in attr"
              :key="index"
              :label="item.dictValue"
            >{{ item.dictLabel }}</el-radio>
          </el-radio-group>
        </div>

        <div class="filtrate-box-show" @click="sizer=!sizer">
          <div>{{ sizer?'收起筛选':'展开筛选'}}</div>
          <div class="filtrate-box-show-img">
            <img v-if="sizer" src="../images/pack.png" alt />
            <img v-else src="../images/unfold.png" alt />
          </div>
        </div>
        <div class="layout" v-show="sizer">
          <div class="layout-item">
            <div class="layout-item-name">已发布平台：</div>
            <div class="layout-item-option">
              <el-checkbox
                :indeterminate="platformShow"
                v-model="platformkAll"
                @change="platformkAllChange"
                style="margin-right: 30px;"
              >全部</el-checkbox>
              <el-checkbox-group v-model="platformValue" @change="platformkedCitiesChange">
                <el-checkbox
                  v-for="(item,index) in platform"
                  :key="index"
                  :label="item.dictValue"
                >{{item.dictLabel}}</el-checkbox>
              </el-checkbox-group>
            </div>
          </div>

          <div class="layout-item">
            <div class="layout-item-name">所在行业：</div>
            <div class="layout-item-option">
              <el-checkbox
                :indeterminate="industryShow"
                v-model="industrykAll"
                @change="industrykAllChange"
                style="margin-right: 30px;"
              >全部</el-checkbox>
              <el-checkbox-group v-model="industryValue" @change="industryCitiesChange">
                <el-checkbox
                  v-for="(item,index) in industry"
                  :key="index"
                  :label="item.dictValue"
                >{{item.dictLabel}}</el-checkbox>
              </el-checkbox-group>
            </div>
          </div>

          <div class="layout-item">
            <div class="layout-item-name">驱动方式：</div>
            <div class="layout-item-option">
              <el-checkbox
                :indeterminate="actuateShow"
                v-model="actuatekAll"
                @change="actuatekAllChange"
                style="margin-right: 30px;"
              >全部</el-checkbox>
              <el-checkbox-group v-model="actuateValue" @change="actuateCitiesChange">
                <el-checkbox
                  v-for="(item,index) in actuate"
                  :key="index"
                  :label="item.dictValue"
                >{{item.dictLabel}}</el-checkbox>
              </el-checkbox-group>
            </div>
          </div>

          <div class="layout-item">
            <div class="layout-item-name">是否授权：</div>
            <el-radio-group v-model="imgAccredit" @input="serachChange">
              <el-radio
                v-for="(item,index) in accredit"
                :key="index"
                :label="item.dictValue"
              >{{ item.dictLabel }}</el-radio>
            </el-radio-group>
          </div>

          <div class="layout-item">
            <div class="layout-item-name">是否转让：</div>
            <el-radio-group v-model="copyright" @input="serachChange">
              <el-radio
                v-for="(item,index) in accredit"
                :key="index"
                :label="item.dictValue"
              >{{ item.dictLabel }}</el-radio>
            </el-radio-group>
          </div>

          <div class="layout-item">
            <div class="layout-item-name">所在地区：</div>
            <div class="layout-item-option">
              <el-checkbox
                :indeterminate="cityShow"
                v-model="citykAll"
                @change="citykAllChange"
                style="margin-right: 30px;"
              >全部</el-checkbox>
              <el-checkbox-group v-model="cityValue" @change="cityCitiesChange">
                <el-checkbox
                  v-for="(item,index) in city"
                  :key="index"
                  :label="item.id"
                >{{ item.name }}</el-checkbox>
              </el-checkbox-group>
            </div>
          </div>
        </div>
      </div>

      <div class="filtrate-box">
        <!-- <Falls ref="falls"></Falls> -->
        <div v-masonry class="container">
          <div
            v-masonry-tile
            v-for="(item, index) in rows"
            :class="`demo-${item}`"
            :key="index"
            @click="detailsChange(item.id)"
          >
            <div class="falls">
              <div class="falls-img">
                <img style="width: 312px;" :src="item.imgUrl" alt />
                <!-- <div class="falls-img-box" v-if="index===0 && show">
                  <img src="../images/falls.png" alt />
                </div>-->
              </div>

              <div class="falls-top">
                <p>{{ item.name }}</p>
                <p>{{item.views}}人浏览</p>
              </div>
              <div class="falls-down">
                <div class="falls-down-left">
                  <div class="falls-down-left-img">
                    <el-avatar :src="item.avatar" :size="22"></el-avatar>
                    <!-- <img :src="item.avatar" alt /> -->
                  </div>
                  <span>{{ item.nickname }}</span>
                </div>
                <div class="falls-down-right">{{ item.attrName }}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
const cityOptions = ["上海", "北京", "广州", "深圳"];
import { Loading } from "element-ui";
import Falls from "../components/Falls";
import { peopleList, getPull, getCom, comment_total } from "@/utils/api";
export default {
  name: "seachView",
  components: {
    Falls
  },
  data() {
    return {
      input3: "",
      radio: 3,
      sizer: false,
      checkedCities: ["上海", "北京"],
      checkAll: false,
      cities: cityOptions,
      isIndeterminate: true,
      demoList: [],
      attr: [],
      platform: [],
      industry: [],
      actuate: [],
      accredit: [],
      city: [],
      rows: [],
      name: "",
      attrValue: [],
      platformValue: [], // 发布平台
      platformkAll: false,
      platformShow: true,
      industryValue: [], // 所在行业
      industrykAll: false,
      industryShow: true,
      actuateValue: [], // 驱动方式
      actuatekAll: false,
      actuateShow: true,
      accreditValue: "", //授权
      accreditValue: "", //转让
      cityValue: [], // 所在地区
      citykAll: false,
      cityShow: true,
      imgAccredit: "",
      copyright: "",
      avatar: "",
      nickname: "",
      msgTotal: "",
      token: "",
      nextp: 1,
      nextpVal: 1,
      fullscreenLoading: true
    };
  },
  created() {
     // 页面头部标题
    document.title = this.$route.meta.title;
    //获取留言条数
    if (localStorage.getItem("token")) {
      comment_total({}, res => {
        localStorage.setItem("msgTotal", res.data);
      });
    }
    console.log("头部", this.$route);
    this.init();
    this.token = localStorage.getItem("token");
    if (this.token) {
      this.avatar = localStorage.getItem("avatar");
      this.nickname = localStorage.getItem("nickname");
      this.msgTotal = localStorage.getItem("msgTotal");
    }
  },

  methods: {
    init() {
      // 获取查询条件
      getPull({}, res => {
        if (res.code === 200) {
          // console.log("条件", res);
          this.attr = res.data.attr;
          this.platform = res.data.platform;
          this.industry = res.data.industry;
          this.actuate = res.data.actuate;
          this.accredit = res.data.accredit;
        }
      });
      getCom({ pid: "0" }, res => {
        this.city = res.data;
        console.log(res);
      });
      // 获取数字人列表
      peopleList({ pageNum: this.nextp }, res => {
        if (res.code === 200) {
          this.rows = res.rows;
          this.nextpVal = Math.ceil(res.total / 10);
          console.log(this.nextpVal);
        }
      });
    },
    // 发布平台
    platformkAllChange(val) {
      if (val) {
        this.platform.forEach(item => {
          this.platformValue.push(item.dictValue);
        });
      } else {
        this.platformValue = [];
      }
      this.platformShow = false;
      this.serachChange();
    },
    platformkedCitiesChange(value) {
      let checkedCount = value.length;
      this.platformkAll = checkedCount === this.platform.length;
      this.platformShow =
        checkedCount > 0 && checkedCount < this.platform.length;
      this.serachChange();
    },
    // 所在行业
    industrykAllChange(val) {
      if (val) {
        this.industry.forEach(item => {
          this.industryValue.push(item.dictValue);
        });
      } else {
        this.industryValue = [];
      }
      this.industryShow = false;
      this.serachChange();
    },
    industryCitiesChange(value) {
      let checkedCount = value.length;
      this.industrykAll = checkedCount === this.industry.length;
      this.industryShow =
        checkedCount > 0 && checkedCount < this.industry.length;
      this.serachChange();
    },
    // 驱动方式
    actuatekAllChange(val) {
      if (val) {
        this.actuate.forEach(item => {
          this.actuateValue.push(item.dictValue);
        });
      } else {
        this.actuateValue = [];
      }
      this.actuateShow = false;
      this.serachChange();
    },
    actuateCitiesChange(value) {
      let checkedCount = value.length;
      this.actuatekAll = checkedCount === this.actuate.length;
      this.actuateShow = checkedCount > 0 && checkedCount < this.actuate.length;
      this.serachChange();
    },
    // 所在地区
    citykAllChange(val) {
      if (val) {
        this.city.forEach(item => {
          this.cityValue.push(item.id);
        });
      } else {
        this.cityValue = [];
      }
      this.cityShow = false;
      this.serachChange();
    },
    cityCitiesChange(value) {
      let checkedCount = value.length;
      this.citykAll = checkedCount === this.city.length;
      this.cityShow = checkedCount > 0 && checkedCount < this.city.length;
      this.serachChange();
    },
    homeChange() {
      this.$router.push({ name: "home" });
    },
    loginChange() {
      var token = localStorage.getItem("token");
      if (token) {
        this.$router.push({ name: "datum" });
      } else {
        this.$message({
          message: "请登录",
          type: "error"
        });
        setTimeout(() => {
          this.$router.push({ name: "login" });
        }, 1200);
      }
    },
    loginLith(){
      this.$router.push({ name: "datum" ,params:{id:2}});
    },
    detailsChange(val) {
      localStorage.setItem("digitalID", val);
      this.$router.push({ name: "details" });
    },
    serachChange() {
      console.log(this.platformValue);
      peopleList(
        {
          name: this.name,
          attrId: this.attrValue,
          platform: this.platformValue,
          actuateIds: this.actuateValue,
          industryIds: this.industryValue,
          imgAccredit: this.imgAccredit,
          copyright: this.copyright,
          provinceIds: this.cityValue
        },
        res => {
          if (res.code === 200) {
            this.rows = res.rows;
            console.log(res);
          }
        }
      );
    },
    // 滚动条触底加载
    getScroll(event) {
      // 滚动条距离底部的距离scrollBottom
      let scrollBottom =
        event.target.scrollHeight -
        event.target.scrollTop -
        event.target.clientHeight;
      // console.log(scrollBottom);
      if (scrollBottom < 5) {
        // this.fullscreenLoading = true;

        this.nextp = this.nextp + 1;
        if (this.nextp > this.nextpVal) {
          return false;
        } else {
          const loading = this.$loading({
            lock: true,
            text: "",
            spinner: "",
            background: "rgba(0, 0, 0, 0.7)"
          });

          peopleList({ pageNum: this.nextp }, res => {
            loading.close();

            if (res.code === 200) {
              res.rows.forEach(item => {
                this.rows.push(item);
              });
            }
          });
        }
      }
    }
  }
};
</script>

<style scoped lang="scss">
.search_box {
  width: 100vw;
  height: 100vh;
  overflow: auto;
}
.head {
  width: 100%;
  height: 280px;
  background: url("../images/search-bg.png");
  background-size: 100% 100%;
  background-position: center;
}
.box {
  max-width: 1920px;
  min-width: 1440px;
  height: 120px;
  margin: auto;
  display: flex;
  // padding-right: 60px;
  &-left {
    padding-left: 2.1%;
    display: flex;
    align-items: center;
    vertical-align: middle;
    width: 29.4%;
    height: 120px;
    cursor: pointer;

    > img {
      width: 100%;
    }
  }
  &-wier {
    width: 0.8px;
    height: 37px;
    margin-top: 42px;
    margin-left: 1.6%;
    background-color: #ffffff2f;
  }
  &-centent {
    width: 20%;
    margin-left: 1.6%;
    // padding-left: 1.6%;
    // border-left: 1px solid #ffffff2f;
    height: 60px;
    margin-top: 30px;
    display: flex;
    align-items: center;
    font-size: 28px;
    font-weight: bold;
    color: #ffffff;
    letter-spacing: 3px;
  }
  &-right {
    // width: 47.8%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 60px;
    &-box {
      width: 140px;
      height: 48px;
      border: 1px solid #ffffff;
      font-size: 18px;
      font-weight: 500;
      color: #ffffff;
      text-align: center;
      line-height: 48px;
      cursor: pointer;
    }
    &-hint {
      // width:34px;
      //     height: 40px;
      margin-right: 20px;
      position: relative;
      cursor: pointer;

      > img {
        width: 21px;
        height: 23px;
      }
      &-num {
        width: 23px;
        height: 23px;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: red;
        position: absolute;
        border-radius: 50%;
        font-size: 12px;
        font-weight: 500;
        color: #ffffff;
        top: -8px;
        right: -13px;
        border: 3px solid #3c7dd8;
      }
    }

    > p {
      font-size: 18px;
      font-weight: 400;
      color: #ffffff;
      cursor: pointer;
    }
    // > img {
    //   width: 60px;
    //   height: 60px;
    //   border-radius: 50%;
    //   cursor: pointer;
    //   margin-left: 20px;
    // }
    &-img {
      width: 60px;
      height: 60px;
      border-radius: 50%;
      cursor: pointer;
      margin-left: 20px;
      cursor: pointer;
      // margin-right: 60px;
      // outline: 2px solid red;
      overflow: hidden;
    }
  }
}
.search {
  width: 42%;
  height: 30%;
  margin: 37px auto 0px;
  background-color: rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  padding: 0 10px;
  &-box {
    width: 66px;
    height: 66px;
    background-color: #0ea5e4;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    > img {
      width: 25px;
      height: 26px;
    }
  }
}

.filtrate {
  max-width: 1920px;
  min-width: 1440px;
  min-height: 87vh;

  margin: 0 auto;
  border-top: 1px solid transparent;
  &-box {
    width: 75%;
    margin: 0 auto;

    margin-top: 30px;
    background: rgb(255, 255, 255);
    padding: 40px 0 10px 40px;
    position: relative;

    &-title {
      font-size: 16px;
      font-weight: 400;
      color: #888888;
      margin-bottom: 30px;
      display: flex;
      align-items: center;
    }
    &-show {
      width: 108px;
      height: 34px;
      border: 1px solid #dddddd;
      position: absolute;
      top: 14px;
      right: 14px;
      background-color: #ffffff;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 16px;
      font-weight: 400;
      color: #333333;
      cursor: pointer;
      &-img {
        width: 8px;
        height: 7px;
        display: flex;
        align-items: center;
        margin-left: 7px;
        > img {
          width: 100%;
        }
      }
    }
  }
}

.layout {
  width: 100%;
  // height: 20px;
  // background-color: red;
  &-item {
    width: 100%;
    display: flex;
    // align-items: center;
    font-size: 16px;
    font-weight: 400;
    color: #888888;
    margin: 15px 0;
    &-name {
      width: 100px;
      margin-right: 20px;
      text-align: right;
      // outline: 2px solid red;
    }
    &-option {
      flex: 1;
      line-height: 30px;
      display: flex;
    }
  }
}

.input-with-select {
  width: 100%;

  background-color: rgb(255, 255, 255);
}
:deep .el-input-group__append {
  height: 66px;
  background-color: #0ea5e4;
}
:deep .el-input__inner {
  height: 66px;
  outline: none;
  border: none;
}
.container {
  width: 100%;
}
.falls {
  margin: 0 34px 20px 0px;
  &-img {
    width: 312px;
    position: relative;
    > img {
      width: 100%;
    }
    &-box {
      position: absolute;
      width: 32px;
      height: 32px;
      background: #ffffff;
      border: 1px solid #dddddd;
      top: 18px;
      right: 18px;
      display: flex;
      justify-content: center;
      align-items: center;
      > img {
        width: 18px;
        height: 18px;
      }
    }
  }

  &-top {
    width: 100%;
    height: 20px;
    display: flex;
    justify-content: space-between;
    font-weight: 500;
    font-size: 16px;
    color: #000000;
    margin-top: 17px;
    margin-bottom: 10px;
    & > p:nth-child(1) {
      width: 180px;
      // height: 20px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    & > p:nth-child(2) {
      font-weight: 500;
      font-size: 16px;
      color: #999999;
      text-align: right;
    }
    p {
      width: 50%;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
    }
  }
  &-down {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 30px;
    &-left {
      display: flex;
      font-size: 14px;

      font-weight: 400;
      color: #333333;

      &-img {
        width: 22px;
        height: 22px;
        overflow: hidden;
        border-radius: 50%;
        margin-right: 6px;
        > img {
          width: 100%;
          height: 100%;
        }
      }
    }
    &-right {
      max-width: 100px;
      height: 26px;
      background: #3a7cd81f;
      font-size: 14px;
      color: #3a7bd8;
      text-align: center;
      line-height: 26px;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      padding: 0 10px;
    }
  }
}
::v-deep {
  .el-avatar > img {
    min-width: 100%;
  }
}
</style>
